package solution

func V1(str string) bool {
	if str == "" {
		return true
	}

	var (
		char  string
		stack = make([]string, 0)
	)

	for _, s := range str {
		char = string(s)

		if char == "{" || char == "(" || char == "[" {
			stack = append(stack, char)
		} else {
			if len(stack) > 0 {
				if char == "}" && stack[len(stack)-1] == "{" {
					stack = stack[:len(stack)-1]
					continue
				}

				if char == ")" && stack[len(stack)-1] == "(" {
					stack = stack[:len(stack)-1]
					continue
				}

				if char == "]" && stack[len(stack)-1] == "[" {
					stack = stack[:len(stack)-1]
					continue
				}
			}

			return false
		}
	}

	if len(stack) > 0 {
		return false
	}

	return true
}
